/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package actioncombination.dao;


import actioncombination.common.util.HibernateUtil;
import actioncombination.logic.agent.knowledge.Knowledge;
import org.hibernate.Session;

/**
 *
 * @author N
 */
public class HibernateDAOFactory extends DAOFactory{

    @Override
    public IActionDAO getActionDAO() {
        return (IActionDAO)instantiateDAO(ActionDAO.class);
    }

    @Override
    public IKnowledgeDAO getKnowledgeDAO() {
         return (IKnowledgeDAO) instantiateDAO(Knowledge.class);
    }

    private GenericHibernateDAO instantiateDAO(Class daoClass) {
        try {
            GenericHibernateDAO dao = (GenericHibernateDAO)daoClass.newInstance();
            dao.setSession(getCurrentSession());
            return dao;
        } catch (Exception ex) {
            throw new RuntimeException("Can not instantiate DAO: " + daoClass, ex);
        }
    }

    // You could override this if you don't want HibernateUtil for lookup
    protected Session getCurrentSession() {
        return HibernateUtil.getInstance().getCurrentSession();
    }

}
